(function () {
    getData()

    function getData() {
        $.ajax({
            url: "http://chst.vip:1234/api/getcoupon"
        }).then(res => {
            createContent(res.result)
        })
    }
    //根据数据创建内筒
    function createContent(data) {
        let html = data.reduce((value, item) => {
            return value += `
                <a couponid=${item.couponId}>
                <img src=${item.couponImg} alt='图片挂了'>
                <p>${item.couponTitle}</p>
                </a>
            `
        }, '')
        $("#main .shop").html(html)
        $("#main a").click(function () {
            let couponid = $(this).attr("couponid");
            location.href = `../pages/coupon_product.html?couponid=${couponid}`
        })
    }
}())